# Maintainer: Sébastien "Seblu" Luttringer <seblu@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Dale Blount <dale@archlinux.org>

pkgname=ulogd
pkgver=2.0.7
pkgrel=3
pkgdesc='Userspace Packet Logging for netfilter'
arch=('x86_64')
url='https://www.netfilter.org/projects/ulogd/'
license=('GPL2')
depends=('libmnl'
         'libnetfilter_acct'
         'libnetfilter_conntrack'
         'libnetfilter_log'
         'libnfnetlink')
backup=('etc/ulogd.conf')
makedepends=('mariadb-libs'
             'libpcap'
             'libdbi'
             'postgresql-libs'
             'sqlite'
             'jansson')
optdepends=('mariadb-libs: MySQL databases support'
            'sqlite: SQLite3 databases support'
            'postgresql-libs: PostgreSQL databases support'
            'libdbi: DBI abstraction databases support'
            'libpcap: PCAP output support'
            'jansson: JSON output support')
validpgpkeys=('C09DB2063F1D7034BA6152ADAB4655A126D292E4') # Netfilter Core Team
source=("https://www.netfilter.org/projects/ulogd/files/$pkgname-$pkgver.tar.bz2"{,.sig}
        "$pkgname.logrotate"
        "$pkgname.conf"
        "$pkgname.service")
md5sums=('2bb2868cf51acbb90c35763c9f995f31'
         'SKIP'
         '50c392d3668ee9c69281f05f55430d0f'
         '2c8cbedb2fb455cba220ca35186ad846'
         '23a13ee4c118cb40b086bdb23d25eac2')

prepare() {
  cd $pkgname-$pkgver
  # apply patch from the source array (should be a pacman feature)
  local filename
  for filename in "${source[@]}"; do
    if [[ "$filename" =~ \.patch$ ]]; then
      msg2 "Applying patch ${filename##*/}"
      patch -p1 -N -i "$srcdir/${filename##*/}"
    fi
  done
  :
}

build() {
  cd $pkgname-$pkgver
  ./configure \
    --prefix=/usr \
    --sbindir=/usr/bin \
    --sysconfdir=/etc \
    --with-mysql \
    --with-pgsql \
    --with-dbi
  make
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  install -dm755 "$pkgdir/usr/share/doc/ulogd"
  install -Dm644 ulogd.conf "$pkgdir/usr/share/doc/ulogd/ulogd.conf"
  install -m644 doc/*.{table,sql} "$pkgdir/usr/share/doc/ulogd"
  cd "$srcdir"
  install -Dm644 $pkgname.service "$pkgdir/usr/lib/systemd/system/$pkgname.service"
  install -Dm644 $pkgname.logrotate "$pkgdir/etc/logrotate.d/$pkgname"
  install -Dm644 $pkgname.conf "$pkgdir/etc/$pkgname.conf"
}

# vim:set ts=2 sw=2 et:
